#pragma once

class CMainFrame;

class CGameBrowserMainFrmProxy
{  
    typedef enum _TitleItemType
    {
        eSYS_Custome_Menu,
        eSYS_Min_Restore,
        eSYS_Max_Restore,
        eSYS_Close,
        eSYS_Icon,
        eSYS_Text,
    }TitleItemType;

    typedef struct _TitleItemInfo
    {
        TitleItemType eItemType;
        BOOL bVisible;
        CRect nPosition;
        int   nItemWidth;
        BOOL bMouseHovered;
        CString strOriginalText;  //Just for eSys_Text;
        CString strVisileText;     //eSys_Text,it will store current visiblie text on caption,for SysButton,it can used to story tooltip.

        _TitleItemInfo()
        {
            bVisible = TRUE;
            nPosition.SetRect(0,0,0,0);
            nItemWidth = 0;
            bMouseHovered = FALSE;
        }

    } TitleItemInfo,*PTitleItemInfo;

private:
    CArray<PTitleItemInfo> m_arraytitleItemList;
    PTitleItemInfo m_pCurrentHoveredItem;

    int m_nSysTemCaptionBarHeight;
    int m_nEdgeWidht;

    BOOL m_bNeedToForceReDrawCaption;

    BOOL m_bCurrentActived;

public:
    CGameBrowserMainFrmProxy( CMainFrame *pMF);
    ~CGameBrowserMainFrmProxy();

private:
    void InitializeItem();
    void ReleaseItem();

private:
    // Implementation
    void DeleteAllTitleItem();
    void RecalcLayoutTitleItem();
    PTitleItemInfo GetTitleItemByType(TitleItemType tType);

    //Draw Title
    void PaintOnMemoryDC(CDC &dcmemery);
    void DrawTitleItem(CDC &dc);

    void DrawIconItem(CDC &dc,PTitleItemInfo pItem);
    void DrawTextItem(CDC &dc,PTitleItemInfo pItem);

    void DrawMinRestoreItem(CDC &dc,PTitleItemInfo pItem);
    void DrawMaxRestoreItem(CDC &dc,PTitleItemInfo pItem);
    void DrawCloseItem(CDC &dc,PTitleItemInfo pItem);

    void DrawCustomMenuItem(CDC &dc,PTitleItemInfo pItem);

    //Operation
    void OnCloseWindow();
    void OnMinimumWindow();
    void OnMaxOrRestoreWindow();
    void OnCustomMenuClicked(CPoint point);
    

    void IdleToCheckCurrentMouseHovered();

    void ForceNcToPaint();

public:
    BOOL FilterMainFrameMessage(UINT message,WPARAM wParam,LPARAM lParam,UINT &uRet);
    void OnIdleToUpdateUI(WPARAM wParam,LPARAM lParam);

private:
    BOOL OnNcLButtonDown(UINT nHitTest,CPoint point);
    BOOL OnNcLButtonUp(UINT nHitTest,CPoint point);
    BOOL OnNcMouseMove(UINT nHitTest,CPoint point);

    BOOL OnNcPaint();
    BOOL OnNcActive(BOOL bActive);
protected:
private:
    CMainFrame *m_pMainFrame;
};